
var ios_package_info = null;
var android_package_info = null;
var u = navigator.userAgent, app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
// $(".app-img").show()
window.onload=function () {
    document.addEventListener('touchstart',function (event) {
        if(event.touches.length>1){
            event.preventDefault();
        }
    });
    var lastTouchEnd=0;
    document.addEventListener('touchend',function (event) {
        var now=(new Date()).getTime();
        if(now-lastTouchEnd<=300){
            event.preventDefault();
        }
        lastTouchEnd=now;
    },false);
    document.addEventListener('gesturestart', function (event) {
        event.preventDefault();
    });
}
// $(".download-btn").click(function () {
//     if (isAndroid) {
//         if (isWeiXin()){
//             $(".tips").show();
//             return false
//         }
//         window.location.href = 'https://sobeyoss.sobeyhealth.com/apk/manliaov1.3.2_release_202007031006_132_jiagu_sign.apk';
//     }
//     if (isIOS) {
//         // window.location.href = ios_package_info;
//         layer.msg('暂不支持iOS下载')
//         return false
//     }
// });
$(".tips").click(function () {
    $(this).hide();
});
var host = '';
var configData = {
    ios_url:'',
    back_url:'',
    app_logo_url:'',
    app_name:'',
    android_downloadname:'',
    ios_downloadname:'',
    android_url:'',
};
$.ajax({
    type: "post",
    url: host + "/api/System/get_appurl",
    cache: false,  //禁用缓存
    dataType: "json",
    success: function (data) {
        if (data.code == 200) {
            var newData = data.data;
            for (var i = 0; i < newData.length;i++){
                if(configData[newData[i].key]==='') {
                    configData[newData[i].key] = newData[i].value;
                }
            }
            $(".app_name,title").html(configData.app_name);
            $(".logo").attr('src',configData.app_logo_url);
            $("body").css({'background':'url('+(configData.back_url||"./bg.png")+')','backgroundSize':'100% auto'});
            // $(".download-btn").html(isIOS?(configData.ios_downloadname||'安卓下载'):(configData.android_downloadname||'苹果下载'))
            $(".download-btn").html('立即下载');
            $(".download-btn").click(function () {
                if (isAndroid) {
                    if (isWeiXin()&&configData.android_url.indexOf('.apk')!=-1){
                        $(".tips").show();
                        return false
                    }
                    if (!configData.android_url) {
                        layer.msg('暂不支持安卓下载');
                        return false
                    }else{
                        window.location.href =  configData.android_url;
                    }
                }
                if (isIOS) {
                    if (!configData.ios_url){
                        layer.msg('暂不支持iOS下载');
                        return false
                    } else{
                        window.location.href = configData.ios_url;
                    }
                }
            });
        }
    }
})

function isWeiXin(){
    //window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息，这个属性可以用来判断浏览器类型
    var ua = window.navigator.userAgent.toLowerCase();
    //通过正则表达式匹配ua中是否含有MicroMessenger字符串
    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
        return true;
    }else{
        return false;
    }
}
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}
function formatUnixtimestamp(unixtimestamp,type) {
    var newunixtimestamp = new Date(unixtimestamp * 1000);
    var year = 1900 + newunixtimestamp.getYear();
    var month = "0" + (newunixtimestamp.getMonth() + 1);
    var date = "0" + newunixtimestamp.getDate();
    var hour = "0" + newunixtimestamp.getHours();
    var minute = "0" + newunixtimestamp.getMinutes();
    var second = "0" + newunixtimestamp.getSeconds();
    if (type==1){
        return year + "-" + month.substring(month.length - 2, month.length) + "-" + date.substring(date.length - 2, date.length)
            + " " + hour.substring(hour.length - 2, hour.length) + ":"
            + minute.substring(minute.length - 2, minute.length)
            + ":"
            + second.substring(second.length - 2, second.length);
    } else{
        return year + "-" + month.substring(month.length - 2, month.length) + "-" + date.substring(date.length - 2, date.length)
    }
}